package com.atguigu.study.controller;

import cn.hutool.core.date.DateUtil;
import com.atguigu.study.service.ChatAssistant;
import com.atguigu.study.service.ChatMemoryAssistant;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Marco
 * @Description
 * @date 2025/8/20 18:42
 * @email 3293336923@qq.com
 */
@Slf4j
@RestController
public class ChatMemoryController {

    @Resource(name = "chat")
    private ChatAssistant  chatAssistant;

    @Autowired
    private ChatMemoryAssistant   chatMessageWindowChatMemory;

    @Autowired
    private  ChatMemoryAssistant   chatTokenWindowChatMemory;

    /***
     *  V1: 没有记忆缓存功能
     * @return
     */
    @GetMapping("/chat/memory/test1")
    public     String    chat(){

        String   answer01  = chatAssistant.chat("你好，我的名字叫Marco");
        log.info("answer01:{}" , answer01);

        String answer02 = chatAssistant.chat("我的名字叫什么");
        log.info("answer02:{}",answer02);

        return  "success:" + DateUtil.now()+"<br>\n\n " +
                "answer01:"+answer01+"<br>\n\n" +
                "answer02:" + answer02;
    }


    /***
     *    MessageWindowChatMemory 实现 聊天记忆 功能
     * @return
     */

    @GetMapping("/chat/memory/test02")
    public     String    chatMessageWindowChatMemory(){

        chatMessageWindowChatMemory.chat(1L, "你好，我的名字叫mysql");
        String answer01 = chatMessageWindowChatMemory.chat(1L, "我的名字是什么?");
        log.info("answer01返回结果:{}" , answer01);

        chatMessageWindowChatMemory.chat(3L , "你好,我的名字叫oracle");
        String answer02 = chatMessageWindowChatMemory.chat(3L, "你好，我的名字是什么?");
        log.info("answer02返回结果:{}" , answer02);

        return "chatMessageWindowChatMemory success"
                + DateUtil.now()+"<br> \n\n  " +
                "answer01:" + answer01 +"<br> \n\n  " +
                "answer02:" + answer02 ;
    }



    @GetMapping("/chat/memory/test03")
    public     String    chatTokenWindowChatMemory(){

        chatTokenWindowChatMemory.chat(1L, "你好，我的名字叫Java");
        String answer01 = chatTokenWindowChatMemory.chat(1L, "我的名字是什么?");
        log.info("answer01返回结果:{}" , answer01);

        chatTokenWindowChatMemory.chat(3L , "你好,我的名字叫C++");
        String answer02 = chatTokenWindowChatMemory.chat(3L, "你好，我的名字是什么?");
        log.info("answer02返回结果:{}" , answer02);

        return "chatMessageWindowChatMemory success"
                + DateUtil.now()+"<br> \n\n  " +
                "answer01:" + answer01 +"<br> \n\n  " +
                "answer02:" + answer02 ;
    }
}
